package com.aliwo.service.impl;

import com.aliwo.domain.Product;
import com.aliwo.service.ProductService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
 * @author xuyayuan
 * @data 2021年07月09日
 */
@Service
public class ProductServiceImpl implements ProductService {
    private static final Logger logger = LoggerFactory.getLogger(ProductServiceImpl.class);
    static List<Product> products = new ArrayList<>();
    static {
        products.add(new Product(1, "ss", "ss", 10));
        products.add(new Product(2, "ee", "ee", 20));
        products.add(new Product(3, "dd", "dd", 30));
    }

    @Override
    public List<Product> getProductDetails() {
        return products;
    }

    @Override
    public Product findByid(@RequestParam("id") Integer id) {
        List<Product> product = products.stream().filter((p) -> p.getId().equals(id) ).collect(Collectors.toList());
        logger.info("service-product findById");
        return product.get(0);
    }
}
